<template>
    <!-- 查看详情 -->
    <el-dialog class="ba-operate-dialog" :model-value="baTable.form.operate ? true : false" @close="baTable.toggleForm">
        <template #header>
            <div class="title" v-drag="['.ba-operate-dialog', '.el-dialog__header']" v-zoom="'.ba-operate-dialog'">{{ t('Info') }}</div>
        </template>
        <el-scrollbar v-loading="baTable.form.loading" class="ba-table-form-scrollbar">
            <div class="ba-operate-form" :class="'ba-' + baTable.form.operate + '-form'">
                <el-descriptions :column="2" border>
                    <el-descriptions-item label="编号">
                        {{ baTable.form.extend!.info.sn }}
                    </el-descriptions-item>
                    <el-descriptions-item label="提交时间">
                        {{ timeFormat(baTable.form.extend!.info.create_time) }}
                    </el-descriptions-item>
                    <el-descriptions-item label="状态">
                        {{ getStatusText(baTable.form.extend!.info.status) }}
                    </el-descriptions-item>
                    <el-descriptions-item label="单位">
                        {{ baTable.form.extend!.info.company.name }}
                    </el-descriptions-item>
                    <el-descriptions-item label="金额">
                        {{ baTable.form.extend!.info.money }}
                    </el-descriptions-item>
                    <el-descriptions-item label="转账途径">
                        {{ baTable.form.extend!.info.transfer_method }}
                    </el-descriptions-item>
                    <el-descriptions-item :width="120" :span="2" label="案件名称">
                        {{ baTable.form.extend!.info.title }}
                    </el-descriptions-item>
                    <el-descriptions-item :width="120" :span="2" label="简要案情">
                        {{ baTable.form.extend!.info.content }}
                    </el-descriptions-item>
                    <el-descriptions-item :width="120" :span="2" label="附件">
                        <el-button type="primary" size="small" v-if="baTable.form.extend!.info.file" @click="onDownload(baTable.form.extend!.info.file)">
                            点击下载 {{ getFileSuffix(baTable.form.extend!.info.file) }} 文件
                        </el-button>
                    </el-descriptions-item>
                    <el-descriptions-item :width="120" :span="2" label="App文件">
                        <el-button type="primary" size="small" v-if="baTable.form.extend!.info.app_file" @click="onDownload(baTable.form.extend!.info.app_file)">
                            点击下载 {{ getFileSuffix(baTable.form.extend!.info.app_file) }} 文件
                        </el-button>
                    </el-descriptions-item>
                    <el-descriptions-item :width="120" :span="2" label="涉案平台信息">
                        <el-tree class="table-el-tree" :data="baTable.form.extend!.info.data1" :props="{ label: 'label', children: 'children' }" />
                    </el-descriptions-item>
                    <el-descriptions-item :width="120" :span="2" label="受害人信息">
                        <el-tree class="table-el-tree" :data="baTable.form.extend!.info.data2" :props="{ label: 'label', children: 'children' }" />
                    </el-descriptions-item>
                    <el-descriptions-item :width="120" :span="2" label="诈骗人信息">
                        <el-tree class="table-el-tree" :data="baTable.form.extend!.info.data3" :props="{ label: 'label', children: 'children' }" />
                    </el-descriptions-item>
                </el-descriptions>
            </div>
        </el-scrollbar>
    </el-dialog>
</template>

<script setup lang="ts">
import { inject } from 'vue'
import { useI18n } from 'vue-i18n'
import type BaTable from '/@/utils/baTable'
import { timeFormat, fullUrl } from '/@/utils/common'

const baTable = inject('baTable') as BaTable

const { t } = useI18n()

const onDownload = (url: string) => {
    if (url) {
        const a = document.createElement('a')
        a.href = fullUrl(url)
        a.download = ''
        a.target = '_blank'
        a.click()
    }
}

const getFileSuffix = (filePath: string) => {
    if (filePath) {
        const arr = filePath.split('.')
        return arr[arr.length - 1]
    }
    return '未知'
}

const getStatusText = (status: number) => {
    // 0待发送，1已接收，2进行中，3挂起，4结束，5取消
    switch (status) {
        case 0:
            return '待发送'
        case 1:
            return '已接收'
        case 2:
            return '进行中'
        case 3:
            return '挂起'
        case 4:
            return '结束'
        case 5:
            return '取消'
        default:
            return '未知'
    }
}

</script>

<style scoped lang="scss">
.table-el-tree {
    :deep(.el-tree-node) {
        white-space: unset;
    }
    :deep(.el-tree-node__content) {
        display: block;
        align-items: unset;
        height: unset;
    }
}
</style>
